function changeNG(url,id,cus_id,cn){	
	var urlaction=url+"modules/customers/add/getNguoiQuanLy?dvi="+id+'&cus_id='+cus_id+'&cn='+cn;
	$.getJSON(urlaction,null,function(data){
		var select = document.getElementById("dsnv");
		select.innerHTML = data;
		});
}
function open_popup_kh(){
	dvi=document.getElementById('donvi_giao').value
		popup("hopdong/popup_kh.php",800,500);
}
function open_popup_chbh(){
	dvi=document.getElementById('donvi_giao').value
	kha_id=document.getElementById('Kha_Id').value
	popup(COREJS._getJsLang('URL')+"/modules/cr/popup_chbh.php?pagetype=popup&kha="+ kha_id + '&dvi='+dvi,800,500);
}
function formatNumber_DB(obj){
	numberFormat = new NumberFormat(obj);
	numberFormat.setSeparators(true, COREJS._getJsLang('separator'), COREJS._getJsLang('decimal'));
	numberFormat.setPlaces(COREJS._getJsLang('lamtron'));
	return  numberFormat.toFormatted();
}
function changeTT(id){
	var block_id = document.getElementById('nkt_block');
	var none_id = document.getElementById('nkt_none');
	var nhachd = document.getElementById('display_nhac_hd');
	if(id==123 || id==122){
		none_id.style.display = "block";
		block_id.style.display = "none";
		nhachd.style.display = 'block';
		document.getElementById('ngayketthuc').value = COREJS._getJsLang('ngayht');
	}
	else{
			none_id.style.display = "none";
			block_id.style.display = "block";
			nhachd.style.display = 'none';
			$('#nhac_hop_dong').val('');
	}
}
function open_ppdmll(){
	dvi = document.getElementById('donvi_giao').value
	var kha_id = document.getElementById('Kha_Id').value;
	if(kha_id!=''){
		var url = COREJS._getJsLang('URL')+'/modules/customers/DmllIndex/popupDmll?pagetype=popup&kha_id=1&kha='+kha_id;
		popup(url,800,500);
	}
	else{
		var url = COREJS._getJsLang('URL')+'/modules/customers/DmllIndex/popupDmll?pagetype=popup&kha_id=1&dvi='+dvi;
		popup(url,800,500);
	}
	
}

$(function() {
    $( "#dialog2" ).dialog({
        autoOpen: false,
        height: 500,
        width:500,
        modal: true
    });
    $(".openp_dialog2").click(function(){
        $( "#dialog2" ).dialog( "open" );
    })
});
function close_popup_nqlk(){
    $( "#dialog2" ).dialog( "close" );
}
function checkform(dinhdang){
	tenhopdong    = document.getElementById('tenhopdong');
	nguoithuchien = document.getElementById('nv_giao');
	donvithuchien = document.getElementById('donvi_giao');
	khachhang     = document.getElementById('khachhang');   
	mahd=document.getElementById('sohopdong');
	start = document.getElementById('ngaybatdau');
	end = document.getElementById('ngayketthuc');
	ngayky = document.getElementById('ngayky');
	giatri = document.getElementById('giatri_');
	// bieu thuc kiem tra rong
	re = /^(\s)*$/i;
	str = RegExp(re);
	if(mahd.value==''){
		alert(COREJS._getJsLang('_MA_HD_CHUA_NHAP'));
		mahd.select();
		return false;
	}
	if(!check_trung_so_hd()){
		return false;	
   }
	if(str.test(tenhopdong.value)){
		alert(COREJS._getJsLang('_TEN_HOP_DONG_CHUA_NHAP'));
		tenhopdong.select();
		return false;
	}
	if(str.test(khachhang.value)){
		alert(COREJS._getJsLang('ALERT_KH_HD'));
		khachhang.select();
		return false;
	}
	if(giatri.value=='' || giatri.value==0){
		alert(COREJS._getJsLang('_GIA_TRI_HOP_DONG_KHONG_DUOC_RONG'));
		jQuery("#giatri").focus();
		return false;
	}
	Ngay_Bat_Dau= (start.value).split(dinhdang);
	ngay_bd=Ngay_Bat_Dau[0];
	thang_bd=Ngay_Bat_Dau[1];
	nam_bd=Ngay_Bat_Dau[2];
	if(end.value!=""){
		Ngay_KT= (end.value).split(dinhdang);
		ngay_kt=Ngay_KT[0];
		thang_kt=Ngay_KT[1];
		nam_kt=Ngay_KT[2];
		if(nam_bd*1 > nam_kt*1){
			alert(COREJS._getJsLang('ALERT_KT_HON_BD'));
			end.focus();
			return false;
		}
		if(nam_bd*1 == nam_kt*1){
			if(thang_bd*1 > thang_kt*1){
				alert(COREJS._getJsLang('ALERT_KT_HON_BD'));
				end.focus();
				return false;
			}
			if(thang_bd*1 == thang_kt*1){
				if(ngay_bd*1 > ngay_kt*1){
					alert(COREJS._getJsLang('ALERT_KT_HON_BD'));
					end.focus();
					return false;
				}
			}
		}
	}
	if(donvithuchien.value=="$$$"){
		alert(COREJS._getJsLang('ALERT_DV_TH'));
		donvithuchien.focus();
		return false;
	}
	if(nguoithuchien.value=="$$$"){
		alert(COREJS._getJsLang('ALERT_NGUOI_TH'));
		nguoithuchien.focus();
		return false;
	}
	else{
		 document.frmhd.submit();
	}
	//return true;
}
function check_trung_so_hd(){
	var ok = true
	var so_hd = jQuery("#sohopdong").val();
	$.ajax({
		async: false,
		url:COREJS._getJsLang('URL')+"/modules/hopdong/add/checkTrungSoHD?so_hd="+so_hd+'&hd=1',
		type: "POST",
		dataType:"json",
		success: function(data){
			if(document.getElementById('so_hd_cu').value==document.getElementById('sohopdong').value){
				ok=true;
			}
			else{
				if(data!=0){
					alert(COREJS._getJsLang('_MA_HOP_DONG_DA_TON_TAI'));
					document.getElementById('sohopdong').focus();
					ok = false
				}
			}
		}
	})
	return ok
}

$(function() {
    $( "#dialogpopupNhacHD" ).dialog({
        autoOpen: false,
        height: 240,
        width:420,
        modal: true
    });
    $(".openppnhachopdong").click(function(){
        $( "#dialogpopupNhacHD" ).dialog( "open" );
    })
});
function check_nhac_hd(){
	solannhac=document.getElementById('solannhac');
	noidungnhac=document.getElementById('noi_dung_nhac');
	if(solannhac.value==''){
		alert(COREJS._getJsLang('_BAN_CHUA_NHAP_SO_LAN_NHAC'));
		solannhac.focus();
		return false;
	}
	if(solannhac.value<=0){	
		alert(COREJS._getJsLang('_SO_LAN_NHAC_PHAI_DUONG'));
		solannhac.focus();
		return false;
	}
	if(noidungnhac.value==''){
		alert(COREJS._getJsLang('_BAN_CHUA_NHAP_NOI_DUNG_NHAC'));
		noidungnhac.focus();
		return false;
	}
	else{
		if(document.getElementById('chukynhac').value==1){
			var text= COREJS._getJsLang('_THANG');
		}
		else{
			var text = COREJS._getJsLang('_NAM');
		}
		document.getElementById('nhac_hop_dong').value=solannhac.value+' '+text;
		document.getElementById('kieunhac_hd').value=document.getElementById('chukynhac').value;
		document.getElementById('solannhac_hd').value=solannhac.value;
		document.getElementById('cosuanhac_hd').value=1;
		document.getElementById('noidungnhac_hd').value=noidungnhac.value;
		$( "#dialogpopupNhacHD" ).dialog( "close" );
	}
}
function themmoi_cvt(hdoid,tab){
	var url=COREJS._getJsLang('URL')+'/modules/congviec/index/add&path=hopdong/edit?p='+hdoid+'&id_hdo='+hdoid+'&tab='+tab;
		window.open(url,"_self");
}
function open_tab_congviec(url,ihdoid,Dvi_Id,Cus_Id,perm_edit,tab){
	 var urlaction=url+"modules/customers/edit/tabCONGVIEC?iHdoId="+ihdoid+'&Dvi_Id='+Dvi_Id+'&Cus_Id='+Cus_Id+'&perm_edit='+perm_edit+'&tab='+tab;
		$.getJSON(urlaction,null,function(data){
			document.getElementById('workrelated').innerHTML = data.html;
			show_page('frmWork', 'row_related', 10, data.total, 'pageInfo_work', 'page_work', 'prevPage_work', 'nextPage_work')
		});
}
function onpen_ttmk(){
	if($('#idmkt').val()!='' && $('#idmkt').val()!=0){
		var url =  COREJS._getJsLang('URL')+ '/modules/marketing/index/view?idmk='+$('#idmkt').val();
		window.open(url, '_blank');
	}
}
function onpen_ttch(){
	if($('#Chb_Id').val()!=''){
		var url =  COREJS._getJsLang('URL')+ '/modules/chbh/index/view?idch='+$('#Chb_Id').val();
		window.open(url, '_blank');
	}
}
function onpen_ttkh(){
	if($('#Kha_Id').val()!=''){
		var url =  COREJS._getJsLang('URL')+ '/modules/customers/edit?view=1&p='+$('#Kha_Id').val();
		window.open(url, '_blank');
	}
}
function onpen_ttdmll(){
	if($('#Dml_Id').val()!=''){
		var url =  COREJS._getJsLang('URL')+ '/modules/customers/edit/editDmll?view=1&p='+$('#Dml_Id').val();
		window.open(url, '_blank');
	}
}